package com.xayy.health.core.websocket;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.messaging.SessionDisconnectEvent;

/**
 * @author Shichenlei
 */
@Component
@Slf4j
public class DissconnectListener implements ApplicationListener {

    /**
     * 连接断开后输出日志信息
     *
     * @param event 事件
     */
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof SessionDisconnectEvent){
            String sessionId= ((SessionDisconnectEvent)event).getSessionId();
            log.info("webscoket dissconnects....sessionId={}，time={}", sessionId, System.currentTimeMillis());
        }
    }
}
